package com.sds.webconsole.impl;


import com.estontorise.gae_filestore.interfaces.DataStoreFile;
import org.sds.webconsole.api.SystemFile;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;

public class SystemFileImpl implements SystemFile {
    private DataStoreFile dataStoreFile;

    protected SystemFileImpl(DataStoreFile dataStoreFile) {
        this.dataStoreFile = dataStoreFile;
    }

    @Override
    public boolean isDirectory() {
        return dataStoreFile.isDirectory();
    }

    @Override
    public boolean isFile() {
        return dataStoreFile.isFile();
    }

    @Override
    public long length() {
        return dataStoreFile.length();
    }

    @Override
    public long lastModified() {
        return dataStoreFile.lastModified();
    }

    @Override
    public String[] list() {
        return dataStoreFile.list();
    }

    @Override
    public SystemFile[] listFiles() {
        DataStoreFile[] dataStoreFiles = dataStoreFile.listFiles();
        SystemFile[] systemFiles = new SystemFile[dataStoreFiles.length];
        for (int i = 0; i < dataStoreFile.length(); i++) {
            systemFiles[i] = new SystemFileImpl(dataStoreFiles[i]);
        }
        return systemFiles;
    }

    @Override
    public boolean mkdirs() {
        return dataStoreFile.mkdirs();
    }

    @Override
    public String getPath() {
        return dataStoreFile.getPath();
    }

    @Override
    public boolean exists() {
        return dataStoreFile.exists();
    }

    @Override
    public InputStream openForRead() throws FileNotFoundException {
        return dataStoreFile.openForRead();
    }

    @Override
    public OutputStream openForWrite() throws FileNotFoundException {
        return dataStoreFile.openForWrite();
    }
}
